//
//  HomePageModel.m
//  qiuShiJiangHu
//
//  Created by xalo on 16/1/23.
//  Copyright © 2016年 糗事江湖项目组. All rights reserved.
//

#define kUser @"user"
#define kIcon @"icon"
#define kLogin @"login"
#define kId @"Id"
#define kVotes @"votes"
#define kUp @"up"
#define kDown @"down"
#define kComments_count @"comments_count"
#define kShare_count @"share_count"
#define kID @"ID"
#define kContent @"content"
#define kImage @"image"

#import "HomePageModel.h"

@implementation HomePageModel


-(void)setValue:(id)value forKey:(NSString *)key
{
    [super setValue:value forKey:key];
    
    
    if ([key isEqualToString:@"user"]) {
        
        self.icon = value[@"icon"];
        
        self.login = value[@"login"];
        
        self.Id = [value[@"id"] integerValue];
    }
    
    if ([key isEqualToString:@"id"]) {
        
        self.ID = [value integerValue];
    }
    
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    //nothing

}


//实现归档反归档两个方法

//归档
- (void)encodeWithCoder:(NSCoder *)aCoder {
    
    [aCoder encodeObject:self.user forKey:kUser];
    [aCoder encodeObject:self.icon forKey:kIcon];
    [aCoder encodeObject:self.login forKey:kLogin];
    [aCoder encodeInteger:self.Id forKey:kId];
    [aCoder encodeObject:self.votes forKey:kVotes];
    [aCoder encodeInteger:self.up forKey:kUp];
    [aCoder encodeInteger:self.down forKey:kDown];
    [aCoder encodeInteger:self.comments_count forKey:kComments_count];
    [aCoder encodeInteger:self.ID forKey:kID];
    [aCoder encodeObject:self.content forKey:kContent];
    [aCoder encodeObject:self.image forKey:kImage];
}

//反归档
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    self = [super init];
    if (self) {
        self.user = [aDecoder decodeObjectForKey:kUser];
        self.icon = [aDecoder decodeObjectForKey:kIcon];
        self.login = [aDecoder decodeObjectForKey:kLogin];
        self.Id = [aDecoder decodeIntegerForKey:kId];
        self.votes = [aDecoder decodeObjectForKey:kVotes];
        self.up = [aDecoder decodeIntegerForKey:kUp];
        self.down = [aDecoder decodeIntegerForKey:kDown];
        self.comments_count = [aDecoder decodeIntegerForKey:kComments_count];
        self.share_count = [aDecoder decodeIntegerForKey:kShare_count];
        self.ID = [aDecoder decodeIntegerForKey:kID];
        self.content = [aDecoder decodeObjectForKey:kContent];
        self.image = [aDecoder decodeObjectForKey:kImage];
    }
    return self;
}




@end
